package com.cw2.behavioral.iterator;

/**
 * 迭代器模式
 */
public class MainTest {
    public static void main(String[] args) {
        MaYuCheng maYuCheng = new MaYuCheng();
        maYuCheng.addFriend("张三");
        maYuCheng.addFriend("李四");
        maYuCheng.addFriend("王五");

        BeautifulMan.Iterator iterator = maYuCheng.getIterator();
        // 获取第一个
        System.out.println(iterator.firstFriend());

        // 获取最后一个
        System.out.println(iterator.lastFriend());


        System.out.println("-----------------");
        // 遍历元素
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
    }

}
